home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / Zoners Half-Life Tools / common / bspfile.h < prev    next >
C/C++ Source or Header  |  2002-11-09  |  12KB  |  396 lines

  1. #ifndef BSPFILE_H__
  2. #define BSPFILE_H__
  3.  
  4. #if _MSC_VER >= 1000
  5. #pragma once
  6. #endif
  7.  
  8. // upper design bounds
  9.  
  10. #define MAX_MAP_HULLS            4
  11. // hard limit
  12.  
  13. #define MAX_MAP_MODELS         400
  14. // variable, but 400 brush entities is very stressful on the engine and network code as it is
  15.  
  16. #define MAX_MAP_BRUSHES       8192
  17. // arbitrary, but large numbers of brushes generally require more lightmap's than the compiler can handle
  18.  
  19. #define MAX_ENGINE_ENTITIES   1024
  20. #define MAX_MAP_ENTITIES      2048
  21. // hard limit, in actuallity it is too much, as temporary entities in the game plus static map entities can overflow
  22.  
  23. #define MAX_MAP_ENTSTRING   (512*1024)
  24. // abitrary, 512Kb of string data should be plenty even with TFC FGD's
  25.  
  26. #define MAX_MAP_PLANES      32767
  27. // (from email): I have been building a rather complicated map, and using your latest 
  28. // tools (1.61) it seemed to compile fine.  However, in game, the engine was dropping
  29. // a lot of faces from almost every FUNC_WALL, and also caused a strange texture 
  30. // phenomenon in software mode (see attached screen shot).  When I compiled with v1.41,
  31. // I noticed that it hit the MAX_MAP_PLANES limit of 32k.  After deleting some brushes
  32. // I was able to bring the map under the limit, and all of the previous errors went away.
  33.  
  34. #define MAX_MAP_NODES        32767
  35. // hard limit (negative short's are used as contents values)
  36. #define MAX_MAP_CLIPNODES    32767
  37. // hard limit (negative short's are used as contents values)
  38.  
  39. #define MAX_MAP_LEAFS         8192
  40. // hard limit (halflife depends on it to setup pvs bits correctly)
  41.  
  42. #define MAX_MAP_VERTS        65535
  43. #define MAX_MAP_FACES        65535
  44. #define MAX_MAP_MARKSURFACES 65535
  45. // hard limit (data structures store them as unsigned shorts)
  46.  
  47. #define MAX_MAP_TEXTURES       512
  48. // hard limit (halflife limitation)
  49.  
  50. #define MAX_MAP_TEXINFO      32767
  51. // hard limit (face.texinfo is signed short)
  52.  
  53. #define MAX_MAP_EDGES       256000
  54. #define MAX_MAP_SURFEDGES   512000
  55. // arbtirary
  56.  
  57. #define DEFAULT_MAX_MAP_MIPTEX      0x400000
  58. // 4Mb of textures is enough especially considering the number of people playing the game
  59. // still with voodoo1 and 2 class cards with limited local memory.
  60.  
  61. #define MAX_MAP_LIGHTING    0x400000
  62. // arbitrary
  63.  
  64. #define MAX_MAP_VISIBILITY  0x200000
  65. // arbitrary
  66.  
  67. // these are for entity key:value pairs
  68. #define MAX_KEY                 32
  69. #define MAX_VALUE             4096
  70. // quote from yahn: 'probably can raise these values if needed'
  71.  
  72. // texture size limit
  73.  
  74. #define MAX_TEXTURE_SIZE     ((256 * 256 * sizeof(short) * 3) / 2)
  75. // this is arbitrary, and needs space for the largest realistic texture plus
  76. // room for its mipmaps.'  This value is primarily used to catch damanged or invalid textures
  77. // in a wad file
  78.  
  79. //=============================================================================
  80.  
  81. #define BSPVERSION  30
  82. #define TOOLVERSION 2
  83.  
  84.  
  85. //
  86. // BSP File Structures
  87. //
  88.  
  89.  
  90. typedef struct
  91. {
  92.     int             fileofs, filelen;
  93. }
  94. lump_t;
  95.  
  96. #define LUMP_ENTITIES      0
  97. #define LUMP_PLANES        1
  98. #define LUMP_TEXTURES      2
  99. #define LUMP_VERTEXES      3
  100. #define LUMP_VISIBILITY    4
  101. #define LUMP_NODES         5
  102. #define LUMP_TEXINFO       6
  103. #define LUMP_FACES         7
  104. #define LUMP_LIGHTING      8
  105. #define LUMP_CLIPNODES     9
  106. #define LUMP_LEAFS        10
  107. #define LUMP_MARKSURFACES 11
  108. #define LUMP_EDGES        12
  109. #define LUMP_SURFEDGES    13
  110. #define LUMP_MODELS       14
  111. #define HEADER_LUMPS      15
  112.  
  113. //#define LUMP_MISCPAD      -1
  114. //#define LUMP_ZEROPAD      -2
  115.  
  116. typedef struct
  117. {
  118.     float           mins[3], maxs[3];
  119.     float           origin[3];
  120.     int             headnode[MAX_MAP_HULLS];
  121.     int             visleafs;                              // not including the solid leaf 0
  122.     int             firstface, numfaces;
  123. }
  124. dmodel_t;
  125.  
  126. typedef struct
  127. {
  128.     int             version;
  129.     lump_t          lumps[HEADER_LUMPS];
  130. }
  131. dheader_t;
  132.  
  133. typedef struct
  134. {
  135.     int             nummiptex;
  136.     int             dataofs[4];                            // [nummiptex]
  137. }
  138. dmiptexlump_t;
  139.  
  140. #define MIPLEVELS   4
  141. typedef struct miptex_s
  142. {
  143.     char            name[16];
  144.     unsigned        width, height;
  145.     unsigned        offsets[MIPLEVELS];                    // four mip maps stored
  146. }
  147. miptex_t;
  148.  
  149. typedef struct
  150. {
  151.     float           point[3];
  152. }
  153. dvertex_t;
  154.  
  155. typedef struct
  156. {
  157.     float           normal[3];
  158.     float           dist;
  159.     planetypes      type;                                  // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
  160. }
  161. dplane_t;
  162.  
  163. typedef enum
  164. {
  165.     CONTENTS_EMPTY = -1,
  166.     CONTENTS_SOLID = -2,
  167.     CONTENTS_WATER = -3,
  168.     CONTENTS_SLIME = -4,
  169.     CONTENTS_LAVA = -5,
  170.     CONTENTS_SKY = -6,
  171.     CONTENTS_ORIGIN = -7,                                  // removed at csg time
  172.     CONTENTS_CLIP = -8,                                    // changed to contents_solid
  173.  
  174.     CONTENTS_CURRENT_0 = -9,
  175.     CONTENTS_CURRENT_90 = -10,
  176.     CONTENTS_CURRENT_180 = -11,
  177.     CONTENTS_CURRENT_270 = -12,
  178.     CONTENTS_CURRENT_UP = -13,
  179.     CONTENTS_CURRENT_DOWN = -14,
  180.  
  181.     CONTENTS_TRANSLUCENT = -15,
  182.     CONTENTS_HINT = -16,     // Filters down to CONTENTS_EMPTY by bsp, ENGINE SHOULD NEVER SEE THIS
  183.  
  184. #ifdef ZHLT_NULLTEX
  185.     CONTENTS_NULL = -17,     // AJM  // removed in csg and bsp, VIS or RAD shouldnt have to deal with this, only clip planes!
  186. #endif
  187.  
  188. #ifdef ZHLT_DETAIL   // AJM
  189.     CONTENTS_DETAIL = -18,  
  190. #endif
  191. }
  192. contents_t;
  193.  
  194. // !!! if this is changed, it must be changed in asm_i386.h too !!!
  195. typedef struct
  196. {
  197.     int             planenum;
  198.     short           children[2];                           // negative numbers are -(leafs+1), not nodes
  199.     short           mins[3];                               // for sphere culling
  200.     short           maxs[3];
  201.     unsigned short  firstface;
  202.     unsigned short  numfaces;                              // counting both sides
  203. }
  204. dnode_t;
  205.  
  206. typedef struct
  207. {
  208.     int             planenum;
  209.     short           children[2];                           // negative numbers are contents
  210. }
  211. dclipnode_t;
  212.  
  213. typedef struct texinfo_s
  214. {
  215.     float           vecs[2][4];                            // [s/t][xyz offset]
  216.     int             miptex;
  217.     int             flags;
  218. }
  219. texinfo_t;
  220.  
  221. #define TEX_SPECIAL     1                                  // sky or slime or null, no lightmap or 256 subdivision
  222.  
  223. // note that edge 0 is never used, because negative edge nums are used for
  224. // counterclockwise use of the edge in a face
  225. typedef struct
  226. {
  227.     unsigned short  v[2];                                  // vertex numbers
  228. }
  229. dedge_t;
  230.  
  231. #define MAXLIGHTMAPS    4
  232. typedef struct
  233. {
  234.     unsigned short  planenum;                              // ZHLT1.6/Zoner: was signed in previous versions
  235.     short           side;
  236.  
  237.     int             firstedge;                             // we must support > 64k edges
  238.     short           numedges;
  239.     short           texinfo;
  240.  
  241.     // lighting info
  242.     byte            styles[MAXLIGHTMAPS];
  243.     int             lightofs;                              // start of [numstyles*surfsize] samples
  244. }
  245. dface_t;
  246.  
  247. #define AMBIENT_WATER   0
  248. #define AMBIENT_SKY     1
  249. #define AMBIENT_SLIME   2
  250. #define AMBIENT_LAVA    3
  251.  
  252. #define NUM_AMBIENTS            4                  // automatic ambient sounds
  253.  
  254. // leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
  255. // all other leafs need visibility info
  256. typedef struct
  257. {
  258.     int             contents;
  259.     int             visofs;                                // -1 = no visibility info
  260.  
  261.     short           mins[3];                               // for frustum culling
  262.     short           maxs[3];
  263.  
  264.     unsigned short  firstmarksurface;
  265.     unsigned short  nummarksurfaces;
  266.  
  267.     byte            ambient_level[NUM_AMBIENTS];
  268. }
  269. dleaf_t;
  270.  
  271. //============================================================================
  272.  
  273. #define ANGLE_UP    -1
  274. #define ANGLE_DOWN  -2
  275.  
  276. //
  277. // BSP File Data
  278. //
  279.  
  280. extern int      g_nummodels;
  281. extern dmodel_t g_dmodels[MAX_MAP_MODELS];
  282. extern int      g_dmodels_checksum;
  283.  
  284. extern int      g_visdatasize;
  285. extern byte     g_dvisdata[MAX_MAP_VISIBILITY];
  286. extern int      g_dvisdata_checksum;
  287.  
  288. extern int      g_lightdatasize;
  289. extern byte     g_dlightdata[MAX_MAP_LIGHTING];
  290. extern int      g_dlightdata_checksum;
  291.  
  292. extern int      g_texdatasize;
  293. extern byte*    g_dtexdata;                                  // (dmiptexlump_t)
  294. extern int      g_dtexdata_checksum;
  295.  
  296. extern int      g_entdatasize;
  297. extern char     g_dentdata[MAX_MAP_ENTSTRING];
  298. extern int      g_dentdata_checksum;
  299.  
  300. extern int      g_numleafs;
  301. extern dleaf_t  g_dleafs[MAX_MAP_LEAFS];
  302. extern int      g_dleafs_checksum;
  303.  
  304. extern int      g_numplanes;
  305. extern dplane_t g_dplanes[MAX_MAP_PLANES];
  306. extern int      g_dplanes_checksum;
  307.  
  308. extern int      g_numvertexes;
  309. extern dvertex_t g_dvertexes[MAX_MAP_VERTS];
  310. extern int      g_dvertexes_checksum;
  311.  
  312. extern int      g_numnodes;
  313. extern dnode_t  g_dnodes[MAX_MAP_NODES];
  314. extern int      g_dnodes_checksum;
  315.  
  316. extern int      g_numtexinfo;
  317. extern texinfo_t g_texinfo[MAX_MAP_TEXINFO];
  318. extern int      g_texinfo_checksum;
  319.  
  320. extern int      g_numfaces;
  321. extern dface_t  g_dfaces[MAX_MAP_FACES];
  322. extern int      g_dfaces_checksum;
  323.  
  324. extern int      g_numclipnodes;
  325. extern dclipnode_t g_dclipnodes[MAX_MAP_CLIPNODES];
  326. extern int      g_dclipnodes_checksum;
  327.  
  328. extern int      g_numedges;
  329. extern dedge_t  g_dedges[MAX_MAP_EDGES];
  330. extern int      g_dedges_checksum;
  331.  
  332. extern int      g_nummarksurfaces;
  333. extern unsigned short g_dmarksurfaces[MAX_MAP_MARKSURFACES];
  334. extern int      g_dmarksurfaces_checksum;
  335.  
  336. extern int      g_numsurfedges;
  337. extern int      g_dsurfedges[MAX_MAP_SURFEDGES];
  338. extern int      g_dsurfedges_checksum;
  339.  
  340. extern void     DecompressVis(const byte* src, byte* const dest, const unsigned int dest_length);
  341. extern int      CompressVis(const byte* const src, const unsigned int src_length, byte* dest, unsigned int dest_length);
  342.  
  343. extern void     LoadBSPImage(dheader_t* header);
  344. extern void     LoadBSPFile(const char* const filename);
  345. extern void     WriteBSPFile(const char* const filename);
  346. extern void     PrintBSPFileSizes();
  347.  
  348. //
  349. // Entity Related Stuff
  350. //
  351.  
  352. typedef struct epair_s
  353. {
  354.     struct epair_s* next;
  355.     char*           key;
  356.     char*           value;
  357. }
  358. epair_t;
  359.  
  360. typedef struct
  361. {
  362.     vec3_t          origin;
  363.     int             firstbrush;
  364.     int             numbrushes;
  365.     epair_t*        epairs;
  366. }
  367. entity_t;
  368.  
  369. extern int      g_numentities;
  370. extern entity_t g_entities[MAX_MAP_ENTITIES];
  371.  
  372. extern void            ParseEntities();
  373. extern void            UnparseEntities();
  374.  
  375. extern void            SetKeyValue(entity_t* ent, const char* const key, const char* const value);
  376. extern const char*     ValueForKey(const entity_t* const ent, const char* const key);
  377. extern int             IntForKey(const entity_t* const ent, const char* const key);
  378. extern vec_t           FloatForKey(const entity_t* const ent, const char* const key);
  379. extern void            GetVectorForKey(const entity_t* const ent, const char* const key, vec3_t vec);
  380.  
  381. extern entity_t* FindTargetEntity(const char* const target);
  382. extern epair_t* ParseEpair();
  383. extern entity_t* EntityForModel(int modnum);
  384.  
  385. //
  386. // Texture Related Stuff
  387. //
  388.  
  389. extern int      g_max_map_miptex;
  390. extern void     dtexdata_init();
  391. extern void CDECL dtexdata_free();
  392.  
  393. extern char*    GetTextureByNumber(int texturenumber);
  394.  
  395. #endif //BSPFILE_H__
  396.